package users

import (
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"
	"smart-health-platforms/pkg"
	"strconv"
	"user_srv/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type FaseLoginLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewFaseLoginLogic(ctx context.Context, svcCtx *svc.ServiceContext) *FaseLoginLogic {
	return &FaseLoginLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 人脸识别登录
func (l *FaseLoginLogic) FaseLogin(req *types.FaseLoginRequest) (resp *types.Response, err error) {
	login, err := l.svcCtx.UserRpc.FaseLogin(l.ctx, &user.FaseLoginRequest{
		Id:    int32(req.Id),
		Image: req.Image,
	})
	if err != nil {
		return nil, err
	}
	token, err := pkg.TokenHandler(strconv.FormatInt(login.UserId, 10))
	if err != nil {
		return respons.Error(400, "token生成失败", err.Error()), err
	}
	return respons.Success(token), nil
}
